package com.qdlc.p2p.dal.model;

import java.math.BigDecimal;
import java.util.Date;

import org.springframework.beans.BeanUtils;

import com.qdlc.p2p.common.exception.AccountException;
import com.qdlc.p2p.dal.dto.TppDifference;
import com.qdlc.p2p.dal.dto.UserIdentify;

public class TppDifferenceModel extends TppDifference {

	/** 当前页数 **/
	private int page;
	/** 每页总数 **/
	private int rows;
	/** 排序 asc/desc **/
	private String order;
	/** 排序字段 **/
	private String sort;
	private String remark;
	
	// 用户托管资金差额详情
	/**
	 * 账户余额
	 */
	private double total;
	/**
	 * 托管账户余额
	 */
	private double tppTotal;
	/**
	 * 余额差额
	 */
	private double differenceTotal;
	/**
	 * 可用余额
	 */
	private double useMoney;
	/**
	 * 托管可用余额
	 */
	private double tppUseMoney;
	/**
	 * 可用余额差额
	 */
	private double differenceUse;
	/**
	 * 冻结总额
	 */
	private double noUseMoney;
	/**
	 * 托管冻结总额
	 */
	private double tppNoUseMoney;
	/**
	 * 总冻结差额
	 */
	private double differenceNoUse;
	/** 添加时间 */
	private Date addTime;
	/** 更新时间 */
	private Date updateTime;
	
	private String tppUserCustId;
	/** 条件查询 */
	private String searchName;
	/**
	 * 处理状态 0：未处理 1：已处理
	 */
	private int status;
	
	private double updateTotal;// 更新账户总额
	private double updateUse;// 更新账户余额
	private double updateNoUse;// 更新账户冻结
	
	private String username;
	private String realname;
	private long userId;

	public static TppDifferenceModel instance(TppDifference tppDifference) {
		TppDifferenceModel model = new TppDifferenceModel();
		BeanUtils.copyProperties(tppDifference, model);
		return model;
	}

	/**
	 * 信用额度申请 校验用户认证状态
	 * 
	 * @param attestation
	 */
	public void validAttestionForAmountApply(UserIdentify attestation, int amount,int applyIngCount) {
		if (attestation.getRealNameStatus() != 1) {
			throw new AccountException("您还没有通过实名认证，请先通过实名认证！", 1);
		}
		if (amount > 10000 || amount <= 0) {
			throw new AccountException("信用额度每次最多申请1万！", 1);
		}
		if(applyIngCount > 0){
			throw new AccountException("您还有未审核的信用额度申请，请等待审核！", 1);
		}
	}


	// 业务方法
	/**
	 * 冻结资金
	 * 
	 * @param money
	 */
	public synchronized void freeze(double money) {
		this.setNoUseMoney(this.getNoUseMoney() + money);
		this.setUseMoney(this.getUseMoney() - money);
	}


	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getSearchName() {
		return searchName;
	}

	public void setSearchName(String searchName) {
		this.searchName = searchName;
	}
    
    /**
     * 可用金额转换为字符串防止数值过大变成科学计数法显示
     * @return
     */
    public String getUseMoneyString() {
    	return new BigDecimal(Double.toString(getUseMoney())).toPlainString();
    }
    /**
     * 托管可用金额转换为字符串防止数值过大变成科学计数法显示
     * @return
     */
    public String getTppUseMoneyString() {
    	return new BigDecimal(Double.toString(getTppUseMoney())).toPlainString();
    }
    /**
     * 托管可用差额转换为字符串防止数值过大变成科学计数法显示
     * @return
     */
    public String getDifferenceUseString() {
    	return new BigDecimal(Double.toString(getDifferenceUse())).toPlainString();
    }

	/**
	 * @return the tppUserCustId
	 */
	public String getTppUserCustId() {
		return tppUserCustId;
	}

	/**
	 * @param tppUserCustId the tppUserCustId to set
	 */
	public void setTppUserCustId(String tppUserCustId) {
		this.tppUserCustId = tppUserCustId;
	}

	public double getTotal() {
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}

	public double getTppTotal() {
		return tppTotal;
	}

	public void setTppTotal(double tppTotal) {
		this.tppTotal = tppTotal;
	}

	public double getDifferenceTotal() {
		return differenceTotal;
	}

	public void setDifferenceTotal(double differenceTotal) {
		this.differenceTotal = differenceTotal;
	}

	public double getUseMoney() {
		return useMoney;
	}

	public void setUseMoney(double useMoney) {
		this.useMoney = useMoney;
	}

	public double getTppUseMoney() {
		return tppUseMoney;
	}

	public void setTppUseMoney(double tppUseMoney) {
		this.tppUseMoney = tppUseMoney;
	}

	public double getDifferenceUse() {
		return differenceUse;
	}

	public void setDifferenceUse(double differenceUse) {
		this.differenceUse = differenceUse;
	}

	public double getNoUseMoney() {
		return noUseMoney;
	}

	public void setNoUseMoney(double noUseMoney) {
		this.noUseMoney = noUseMoney;
	}

	public double getTppNoUseMoney() {
		return tppNoUseMoney;
	}

	public void setTppNoUseMoney(double tppNoUseMoney) {
		this.tppNoUseMoney = tppNoUseMoney;
	}

	public double getDifferenceNoUse() {
		return differenceNoUse;
	}

	public void setDifferenceNoUse(double differenceNoUse) {
		this.differenceNoUse = differenceNoUse;
	}

	public Date getAddTime() {
		return addTime;
	}

	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public double getUpdateTotal() {
		return updateTotal;
	}

	public void setUpdateTotal(double updateTotal) {
		this.updateTotal = updateTotal;
	}

	public double getUpdateUse() {
		return updateUse;
	}

	public void setUpdateUse(double updateUse) {
		this.updateUse = updateUse;
	}

	public double getUpdateNoUse() {
		return updateNoUse;
	}

	public void setUpdateNoUse(double updateNoUse) {
		this.updateNoUse = updateNoUse;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}
    
    
}
